package edu.gatech.stolen.tea;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ItemDisplayActivity extends Activity {
	
	public static final String TAG = "Item Display Page";
	
	private TextView nameText;
	private TextView locationText;
	private TextView dateGivenText;
	private TextView dateDueText;
	private TextView descriptionText;
	private Button backButton;
	private Button editButton;
	private Button deleteButton;
	private ToDoItem yourItem;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	Log.v(TAG, "Activity State: onCreate()");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewitem);
        
        yourItem = ItemManager.getCurrentItem();
        
        nameText = (TextView) findViewById(R.id.tItemNameTextView_viewitem);
    	locationText = (TextView) findViewById(R.id.tItemLocationTextView_viewitem);
    	dateGivenText = (TextView) findViewById(R.id.tItemDateGivenTextView_viewitem);
    	dateDueText = (TextView) findViewById(R.id.tItemDueDateTextView_viewitem);
    	descriptionText = (TextView) findViewById(R.id.tItemDescriptionTextView_viewitem);
    	backButton = (Button) findViewById(R.id.bBackButton_viewitem);
    	editButton = (Button) findViewById(R.id.bEditButton_viewitem);
    	deleteButton = (Button) findViewById(R.id.bDeleteButton_viewitem);
    	
    	nameText.setText(yourItem.getName());
    	locationText.setText(yourItem.getLocation());
    	dateGivenText.setText(yourItem.getDateGiven().getDate());
    	dateDueText.setText(yourItem.getDueDate().getDate());
    	descriptionText.setText(yourItem.getDescription());
    	
    	backButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				onBackButtonClicked();
				
			}
		});
    	
    	editButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				onEditButtonClicked();
				
			}
		});
    	
    	deleteButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				onDeleteButtonClicked();
				
			}
		});
    	
    }
    
    public void onBackButtonClicked() {
    	
    	Log.v(TAG, "Back Button Clicked");
    	goToItemDisplayListPage();
    	
    }
    
    public void onEditButtonClicked() {
    	
    	Log.v(TAG, "Edit Button Clicked");
    	goToEditItemPage();
    	
    }
    
    public void onDeleteButtonClicked() {
    	
    	Log.v(TAG, "Delete Button Clicked");
    	goToItemDisplayListPage();
    	
    }
    
    public void goToItemDisplayListPage() {
    	
    	ItemManager.currentItemReset();
    	Intent i = new Intent(this, ItemDisplayListActivity.class);
    	startActivity(i);
    	
    }
    
    public void goToEditItemPage() {
    	
    	Intent i = new Intent(this, EditItemActivity.class);
    	startActivity(i);
    	
    }
}